package inherit;

import javax.naming.Name;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: XMQ
 * Date: 2022-05-13
 * Time: 15:54
 */
/*
    继承里各成员的运行顺序和特性
 */
class Animal{
    public String name;
    public int age;

    static {
        System.out.println("Animal的静态代码块");
    }
    {
        System.out.println("Animal的实例代码块");
    }
    public Animal(){
        System.out.println("Animal不带参数的构造方法");
    }

    public Animal(String name, int age){
        this.name = name;
        this.age = age;
    }

    public void eat(){
        System.out.println(name+"正在吃饭！");
    }
}
class Dog extends Animal{
//    public String name;
//    public int age;
    public float weight;

    static {
        System.out.println("Dog的静态代码块");
    }
    {
        System.out.println("Dog的实例代码块");
    }
    public Dog(){
        //super();//默认提供
        System.out.println("Dog的构造方法");
    }

    public Dog(String name,int age,float weight){
        //super()只能在第一行
        super(name,age);//显示调用父类的函数，来初识化此时子类继承过来的父类的属性
        this.weight = weight;
    }

//    public void eat(){
//        System.out.println(name+"正在吃饭！");
//    }
    public void bark(){
        System.out.println(name+"汪汪汪！");
    }
}
class Cat extends Animal{
    public Cat(String name, int age) {
        super(name, age);
    }
//    public String name;
//    public int age;


//    public void eat(){
//        System.out.println(name+"正在吃饭！");
//    }
    public void miaomiao(){
        System.out.println(name+"正在喵喵喵");
    }
}
public class Test {
    public static void main(String[] args) {
        Dog dog = new Dog();
    }
    public static void main1(String[] args) {
        Dog dog = new Dog("hah",2,10.5f);
        dog.name = "狗子";
        dog.eat();
        dog.bark();
    }
}
